<template>
  <a-card :bordered="false">
      <!--<a-tabs v-model="bizTaskType" @change="handleChangeTabs">
      <a-tab-pane key="0" tab="所有通知单">
      </a-tab-pane>
      <a-tab-pane key="1">
        <span slot="tab">
          <a-badge :count="doTotal">
            待我处理&nbsp;&nbsp;&nbsp;
          </a-badge>
        </span>
      </a-tab-pane>
      <a-tab-pane key="2" tab="我发起的">
        <span slot="tab">
          <a-badge :count="myTotal">
            我发起的&nbsp;&nbsp;&nbsp;
          </a-badge>
        </span>
      </a-tab-pane>
    </a-tabs>-->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <a-input placeholder="请输入单据编号" v-model="queryParam.billNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="档案大类">
              <j-dict-select-category v-model="queryParam.docBigCategory" placeholder="请选择档案大类" parentCode="A04" :async="true" @input="modifyCategory"/>
            </a-form-item>
          </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="档案小类">
                <j-dict-select-category :disabled="!queryParam.docBigCategory" v-model="queryParam.docSmallCategory" placeholder="请选择档案小类" :parentCode="queryParam.docBigCategory" :async="true"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="档案所属团队">
                <select-team-input  :multi="false" :tdlx="3" :teamType="0" v-model="queryParam.docTeamId"  placeholder="请选择档案所属团队" queryType="all"/>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--<a-button type="primary" icon="download" @click="handleExportXls('档案查阅单')" :disabled="isDisabledAuth('erpOaDocReferenceBill:export')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpOaDocReferenceBill:import')">导入</a-button>
      </a-upload>
      -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpOaDocReferenceBill:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom" >
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;margin-top:20px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{getCheckboxProps:getCheckboxProps,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="billNo" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <span slot="action" slot-scope="text, record">
          <template v-if="record.isBack=='0'">
          <a-popconfirm title="确定归还吗?" @confirm="() => backRequest(record)">
            <a-button type="primary" size="small" :disabled="isDisabledAuth('erpCarInfo:backCar')">归还</a-button>
          </a-popconfirm>
        </template>
        </span>
      </a-table>
    </div>

    <erp-oa-doc-reference-bill-modal ref="modalForm" @ok="modalFormOk"></erp-oa-doc-reference-bill-modal>
    <bpm-biz-task-deal-modal ref="taskDealModal" :path="path" :formData="formData" @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
    <process-config-modal ref="processConfig" @ok="handleSuccess"></process-config-modal>
    <ErpOaDocBaseInfoPenetrate ref="docRef"></ErpOaDocBaseInfoPenetrate>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import {JeecgBpmListMixin} from '@/mixins/JeecgBpmListMixin'
  import BpmBizTaskDealModal from "@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue";
  import BpmProcessTrackModal from "@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue";
  import BizTaskNotifyModal from "@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue";
  import BizTaskNotifyMeModal from "@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue";
  import ProcessConfigModal from '@/views/scy/components/ProcessConfigModal'
  import ErpOaDocReferenceBillModal from './modules/ErpOaDocReferenceBillModal'
  import { getAction,postAction,putAction } from '@/api/manage'
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import JDictSelectCategory from '@/components/dict/JDictSelectCategory.vue'
  import ErpOaDocBaseInfoPenetrate from '@/views/scy/penetrate/ErpOaDocBaseInfoPenetrate'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'

  let dictOptions={}
  let that=this

  export default {
    name: 'ErpOaDocReferenceBillList',
    mixins:[JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpOaDocReferenceBillModal,
      BpmBizTaskDealModal,
      BpmProcessTrackModal,
      BizTaskNotifyModal,
      BizTaskNotifyMeModal,
      ProcessConfigModal,
      JDictSelectCategory,
      ErpOaDocBaseInfoPenetrate,
      SelectTeamInput
    },
    data () {
      return {
        description: '档案查阅单管理页面',
        //表头
        columns:[],
        /* 排序参数 */
        isorter: {
          column: 'billNo',
          order: 'desc'
        },
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
         
          {
            title:'单据编号',
            align:"center",
            width:200,
            scopedSlots: {customRender: 'billNo'},
            dataIndex: 'billNo',
          },
          {
            title:'申请人',
            align:"center",
            width:100,
            dataIndex: 'employeeId_dictText',
          },
          {
            title:'档案大类',
            align:"center",
            width:100,
            dataIndex: 'docBigCategory_dictText',
          },
          {
            title:'档案小类',
            align:"center",
            width:200,
            dataIndex: 'docSmallCategory_dictText',
          },
          {
            title:'文件名称',
            align:"center",
            width:200,
            dataIndex: 'docName',
            customRender:function (text,record) {
              if(record.docBigCategory=='A04A01' || record.docBigCategory=='A04A02'){
                return filterMultiDictText(dictOptions['docBaseInfo'], text + '')
              }else{
                return ''
              }
            }
          },
          {
            title:'密级',
            align:"center",
            width:100,
            dataIndex: 'docClassification_dictText',
          },
          {
            title:'档案所属团队',
            align:"center",
            width:200,
            dataIndex: 'docTeamId_dictText',
          },
          {
            title:'借阅日期',
            align:"center",
            width:200,
            dataIndex: 'referenceTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'归还日期',
            align:"center",
            width:200,
            dataIndex: 'backTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'审核状态',
            align:"center",
            dataIndex: 'bpmStatus_dictText',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:160,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/oa/doc/erpOaDocReferenceBill/allList?bpmStatus=3",
          delete: "/api/erp/oa/doc/erpOaDocReferenceBill/delete",
          deleteBatch: "/api/erp/oa/doc/erpOaDocReferenceBill/deleteBatch",
          exportXlsUrl: "/api/erp/oa/doc/erpOaDocReferenceBill/exportXls",
          importExcelUrl: "/api/erp/oa/doc/erpOaDocReferenceBill/importExcel",
          bizCount: "/api/erp/oa/doc/erpOaDocReferenceBill/bizCount",
          back:"/api/erp/oa/doc/erpOaDocReferenceBill/back"
        },
        //代码生成后需手动设置流程编码
        flowCode: 'onl_erp_oa_doc_reference_bill',
        formUrl: "/oa/doc/modules/ErpOaDocReferenceBillForm",
        formUrlMobile: "",
        beanName:"erpOaDocReferenceBillServiceImpl",
        superFieldList:[],
        
      }
    },
    created() {
      this.initDictConfig();
      this.getSuperFieldList();

    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      backRequest(record){
        putAction(this.url.back, { id:record.id}).then(res => {
          if (res.success) {
            this.$message.success(res.message);
            this.loadData();
          }
        })
      },
      modifyCategory(data){
        if(data){
          if(this.queryParam.docSmallCategory){
            this.$set(this.queryParam,"docSmallCategory",null);
          }
        }
      },
      handleDetail: function (record) {
        this.$router.push({
          path: `/oa/doc/ErpOaDocReferenceBillListDetail/`+record.id,
        })
      },
      //查看详情
      getDetail(id) {
        this.$router.push({
          path: `/oa/doc/ErpOaDocReferenceBillListDetail/`+id,
        })
      },
      initDictConfig(){
        initDictOptions('erp_oa_doc_base_info,bill_no,id').then((res) => {
          if (res.success) {
            this.$set(dictOptions, 'docBaseInfo', res.result)
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'bpmStatus',text:'流程状态',dictCode:''})
        fieldList.push({type:'Text',value:'bpmBizTitle',text:'流程标题',dictCode:''})
        fieldList.push({type:'string',value:'billNo',text:'单据编号',dictCode:''})
        fieldList.push({type:'string',value:'departId',text:'申请部门',dictCode:''})
        fieldList.push({type:'string',value:'employeeId',text:'申请人',dictCode:''})
        fieldList.push({type:'string',value:'docBigCategory',text:'档案大类',dictCode:''})
        fieldList.push({type:'string',value:'docSmallCategory',text:'档案小类',dictCode:''})
        fieldList.push({type:'string',value:'docName',text:'文件名称',dictCode:''})
        fieldList.push({type:'string',value:'docClassification',text:'密级',dictCode:'secrecy_level'})
        fieldList.push({type:'string',value:'docAddress',text:'存放位置',dictCode:''})
        fieldList.push({type:'string',value:'docTeamId',text:'档案所属团队',dictCode:''})
        fieldList.push({type:'string',value:'isOutside',text:'是否外带',dictCode:''})
        fieldList.push({type:'date',value:'referenceTime',text:'借阅时间'})
        fieldList.push({type:'BigDecimal',value:'number',text:'份数',dictCode:''})
        fieldList.push({type:'date',value:'backTime',text:'预计归还时间'})
        fieldList.push({type:'Text',value:'referenceReason',text:'借阅事由',dictCode:''})
        fieldList.push({type:'Text',value:'attachment',text:'附件',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
